set nu rnu
set nowrap
set cursorline
set hlsearch
syntax on
set tabstop=4
set expandtab
set modifiable
set shiftwidth=4
set foldmethod=manual

call plug#begin('/home/loveuer/.config/nvim/plugged')

" colorscheme
Plug 'jacoborus/tender'
Plug 'nlknguyen/papercolor-theme'

" base funcs
Plug 'scrooloose/nerdtree'
Plug 'vim-airline/vim-airline'
Plug 'mhinz/vim-startify'
Plug 'jiangmiao/auto-pairs'
Plug 'tpope/vim-repeat'
Plug 'tpope/vim-surround'
Plug 'easymotion/vim-easymotion'
Plug 'tpope/vim-commentary'
Plug 'kien/rainbow_parentheses.vim'

" support tsx and jsx highlight
Plug 'leafgarland/typescript-vim'
Plug 'peitalin/vim-jsx-typescript'

" language func
Plug 'fatih/vim-go'

" completion
Plug 'neoclide/coc.nvim', {'branch': 'release'}

call plug#end()

"################################################
" vim auto formatter on saving files
" au Bufwrite * :Autoformat
"################################################

"#####################################################
let g:startify_bookmarks = [{'c':'/home/loveuer/.config/nvim/init.vim'}, {'r':'/home/loveuer/.zshrc'}]
"#####################################################
"
"#############################
nmap <C-n> :NERDTreeToggle<CR>
"#############################
"
"#############################
nmap ss <Plug>(easymotion-s2)
"#############################
"
"####################################
" auto do GoImports on saving go file
let g:go_fmt_command = "goimports"
let g:go_def_mode='gopls'
let g:go_info_mode='gopls'
"####################################
"
"##############
" set the theme
set background=dark
color PaperColor
set laststatus=2
"##############
"############################################
" for Plug -> rainbow_parentheses
let g:rbpt_colorpairs = [
            \ ['brown',       'RoyalBlue3'],
            \ ['Darkblue',    'SeaGreen3'],
            \ ['darkgray',    'DarkOrchid3'],
            \ ['darkgreen',   'firebrick3'],
            \ ['darkcyan',    'RoyalBlue3'],
            \ ['darkred',     'SeaGreen3'],
            \ ['darkmagenta', 'DarkOrchid3'],
            \ ['brown',       'firebrick3'],
            \ ['gray',        'RoyalBlue3'],
            \ ['darkmagenta', 'DarkOrchid3'],
            \ ['Darkblue',    'firebrick3'],
            \ ['darkgreen',   'RoyalBlue3'],
            \ ['darkcyan',    'SeaGreen3'],
            \ ['darkred',     'DarkOrchid3'],
            \ ['red',         'firebrick3'],
            \ ]
let g:rbpt_max = 16
let g:rbpt_loadcmd_toggle = 0
au VimEnter * RainbowParenthesesToggle
au Syntax * RainbowParenthesesLoadRound
au Syntax * RainbowParenthesesLoadSquare
au Syntax * RainbowParenthesesLoadBraces
"############################################
"
"#######################################################################################
" copy from https://github.com/PegasusWang/vim-config/blob/master/config/plugins/coc.vim
let g:coc_global_extensions = [
            \'coc-snippets',
            \'coc-python',
            \'coc-json',
            \'coc-pairs',
            \'coc-eslint',
            \'coc-prettier',
            \'coc-angular',
            \'coc-html',
            \'coc-css',
            \'coc-tsserver',
            \]
inoremap <silent><expr> <TAB>
            \ pumvisible() ? coc#_select_confirm() :
            \ coc#expandableOrJumpable() ? "\<C-r>=coc#rpc#request('doKeymap', ['snippets-expand-jump',''])\<CR>" :
            \ <SID>check_back_space() ? "\<TAB>" :
            \ coc#refresh()
inoremap <expr> <S-Tab> pumvisible() ? "\<C-p>" : "\<S-Tab>"
function! s:check_back_space() abort
    let col = col('.') - 1
    return ! col || getline('.')[col - 1] =~? '\s'
endfunction
augroup user_plugin_coc
    autocmd!
    autocmd CompleteDone * if pumvisible() == 0 | pclose | endif
augroup END
" use <c-space>for trigger completion
inoremap <silent><expr> <C-space> coc#refresh()
" Movement within 'ins-completion-menu'
imap <expr><C-j>   pumvisible() ? "\<Down>" : "\<C-j>"
imap <expr><C-k>   pumvisible() ? "\<Up>" : "\<C-k>"
" Scroll pages in menu
inoremap <expr><C-f> pumvisible() ? "\<PageDown>" : "\<Right>"
inoremap <expr><C-b> pumvisible() ? "\<PageUp>" : "\<Left>"
imap     <expr><C-d> pumvisible() ? "\<PageDown>" : "\<C-d>"
imap     <expr><C-u> pumvisible() ? "\<PageUp>" : "\<C-u>"
" Use `[c` and `]c` to navigate diagnostics
nmap <silent> [c <Plug>(coc-diagnostic-prev)
nmap <silent> ]c <Plug>(coc-diagnostic-next)
" Remap keys for gotos
nmap <silent> gd <Plug>(coc-definition)
nmap <silent> gy <Plug>(coc-type-definition)
nmap <silent> gi <Plug>(coc-implementation)
nmap <silent> gr <Plug>(coc-references)
nmap gs <Plug>(coc-git-chunkinfo)
nmap [g <Plug>(coc-git-prevchunk)
nmap ]g <Plug>(coc-git-nextchunk)
" show commit contains current position
nmap gC <Plug>(coc-git-commit)
" Use K to show documentation in preview window
nnoremap <silent> K :call <SID>show_documentation()<CR>
function! s:show_documentation()
    if (index(['vim', 'help'], &filetype) >= 0)
        execute 'h '.expand('<cword>')
    else
        let l:found = CocAction('doHover')
    endif
endfunction
"#######################################################################################
